package com.shzu.jwc.ty.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.shzu.jwc.ty.common.Msg;
import com.shzu.jwc.ty.bean.SystemNotice;
import com.shzu.jwc.ty.service.SystemNoticeservice;

@Controller
@RequestMapping("systemnotice")
public class SystemNoticecontroller {
	@Autowired
	SystemNoticeservice systemNoticeservice;
	
	@RequestMapping("/notice.action")
	public String shownotice(@RequestParam(value="pn",defaultValue="1") Integer pn,Model model)
	{
		PageHelper.startPage(pn, 20);
		List<SystemNotice> data=systemNoticeservice.getnotice(0);
		PageInfo<SystemNotice> pageinfo=new PageInfo<SystemNotice>(data,20);
		model.addAttribute("pageinfo", pageinfo);
		return "systemnotice/notice";
	}
	
	@ResponseBody
	@RequestMapping("/insertnotice.action")
	public Msg insertnotice(SystemNotice systemnotice)
	{
		try {
			systemnotice.setSystemNoticeStatue(0);
			systemNoticeservice.insert(systemnotice);
			return Msg.success("插入成功");
		}catch(Exception ex)
		{
			return Msg.error("插入失败,"+ex.getMessage());
		}
	}

	@ResponseBody
	@RequestMapping("/deletenotice.action")
	public Msg deletenotice(@RequestParam("systemNoticeId")Integer systemNoticeId)
	{
		try {
			systemNoticeservice.delete(systemNoticeId);
			return Msg.success("操作成功");
		}catch(Exception ex)
		{
			return Msg.error("操作失败,"+ex.getMessage());
		}
	}
	
	@ResponseBody
	@RequestMapping("/updatenotice.action")
	public Msg updatenotice(@RequestParam("systemNoticeId")Integer systemNoticeId) 
	{
		return Msg.success("操作成功").add("systemNotice", systemNoticeservice.getone(systemNoticeId));
	}
	
	@ResponseBody
	@RequestMapping("/updatefun.action")
	public Msg updatefun(SystemNotice systemnotice) 
	{
		try {
			systemnotice.setSystemNoticeStatue(0);
			systemNoticeservice.update(systemnotice);
			return Msg.success("操作成功");
		}catch(Exception ex)
		{
			return Msg.error("操作失败,"+ex.getMessage());
		}
	}
	

}
